package com.bwie.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.mapper.TbProdMapper;
import com.bwie.pojo.TbProd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author:Max
 * @Date: 2024/8/9 19:00
 * @Description
 **/
@Component
@Slf4j
public class ProdDownTask {
    @Autowired
    TbProdMapper tbProdMapper;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void prodDownTask(){
        log.info("开始执行商品下架任务");

        List<TbProd> tbProds = tbProdMapper.selectList(new QueryWrapper<TbProd>().lambda()
                .eq(TbProd::getDownType, 1).eq(TbProd::getProdStatus, 1)
                .le(TbProd::getDownTime, new Date()));


        for (TbProd tbProd : tbProds) {
            tbProd.setProdStatus(0);
            tbProdMapper.updateById(tbProd);
        }

        log.info("商品下架任务执行完毕~~~~~~~~~~~~~~~~~~~~~");
    }




}
